<html>
<head><meta charset="utf-8"><title>pretty-print without space · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pretty-print.20without.20space.html">pretty-print without space</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244823055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/pretty-print%20without%20space/near/244823055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pretty-print.20without.20space.html#244823055">(Jul 03 2021 at 20:36)</a>:</h4>
<p>How do I pretty-print a string without a space/newline after it in <code>rustc_ast_pretty</code>? <code>self.word(mystring);</code> seems to add a space. However, elsewhere in <code>rustc_ast_pretty</code> where it is used, it does not generate a space (e.g., for <code>::</code>s in paths).</p>
<p>I tried instead calling <code>self.word_space(mystring);</code> to see what would happen, and that generates <em>two</em> spaces, which doesn't seem right.</p>
<p>I looked through the sources for <code>rustc_ast_pretty::pp::Printer</code>, but I was unable to figure out what I should use instead.</p>



<a name="244823066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/pretty-print%20without%20space/near/244823066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pretty-print.20without.20space.html#244823066">(Jul 03 2021 at 20:37)</a>:</h4>
<p>The specific code I'm working on is <a href="https://github.com/rust-lang/rust/blob/96859dbaf6229f131fbd427a32aaa95d4f9cb132/compiler/rustc_ast_pretty/src/pprust/state.rs#L498">here</a>. I'm trying to change the line <code>self.word(token_str);</code> so that it does not emit a space for certain tokens.</p>



<a name="244824442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/pretty-print%20without%20space/near/244824442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pretty-print.20without.20space.html#244824442">(Jul 03 2021 at 21:10)</a>:</h4>
<p>Ah, I think I may have figured it out. I'm waiting on a build to confirm it, but it seems that <code>print_tts()</code> adds a space if <code>tt_prepend_space</code> returns true, which it was for <code>token::Dollar</code>.</p>



<a name="244825514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/pretty-print%20without%20space/near/244825514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pretty-print.20without.20space.html#244825514">(Jul 03 2021 at 21:38)</a>:</h4>
<p>Yep, that fixed it!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>